<template>
	<view class="myfriend u-skeleton">
		<u-navbar title="我的好友" :background="{
			'backgroundColor':'#fff'
		}" :is-fixed='true' :borderBottom="false" class="u-skeleton-rect">
		</u-navbar>
		<view class="top">
			<view class="item" v-for="(item,index) in list" :key="index"
			@click="select(index)" :style="{
				'background':current == index ? '#fff' : ''
			}">{{item.title}} ({{friendObj[item.type]}})</view>
		</view>
		<view class="content-box">
			<diy-scorll :Empty='friendList.length ? false : true' :status = 'status' @scrolltolower='getmanager' @refresherrefresh='refresherrefresh' :is_display= 'friendList.length'>
				<view class="item" v-for="(item,index) in friendList" :key="index">
					<view class="left">
						<u-avatar :src="$util.img(item.avatar)" :size = "80" ></u-avatar>
					</view>
					<view class="right">
						<view class="title">{{item.nickname}}</view>
						<view class="name">
							<text style="margin-right: 30rpx;">lv.{{item.is_invite}}</text>
							<text>{{item.level_name}}</text>
						</view>
					</view>
				</view>
			</diy-scorll>
		</view>
		<u-skeleton :loading="loding" :animation="true" bgColor="#FFF"></u-skeleton>
	</view>
</template>
<script>
	export default {
		data() {
			return {
				loding: true, //初始化骨架屏展示
				// 好友
				list:[{
					title:'全部好友',
					type:'all'
				},{
					title:'未达标',
					type:'no_invite'
				},{
					title:'已达标',
					type:'is_invite'
				}],
				// 列表下面文字状态
				status:'loadmore',
				// 选中的参数
				current:0,
				// 好友列表
				friendList:[],
				//好友数量
				friendObj:{}
			}
		},
		onShow() {
			this.refresherrefresh();
		},
		methods: {
			//数据切换
			select(index){
				this.current = index;
				this.refresherrefresh();
			},
			// 下拉双薪
			refresherrefresh(callback){
				this.page = {
					page:1,
					page_size:8,
				},
				this.getmanager(callback);
			},
			// 或许商品列表
			getmanager(callback){
				this.$http.asyncSendrequest({
					url:'/profile/inviteList',
					data:{
						type:this.current,
						...this.page
					},
					success:res=>{
						if(res.code == '0') {
							if(this.page.page == 1) this.friendList = [];
							this.friendObj = res.data.count;
							if(res.data.list.length){
								this.friendList = this.friendList.concat(res.data.list);
								this.page.page += 1;
							} else {
								//下面加载的文字
								this.status = 'nomore';
							}
							if(typeof callback == 'function') callback();
							this.loding = false;
						}
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.nav-right {
		margin-right: 30rpx;
	}
	.p-content{
		width: 90vw;
		min-height: 150rpx;
		padding: 30rpx;
		background: #fff;
		border-radius: 20rpx;
		display: flex;
		align-items: center;
		.box{
			width: calc(100% - 130rpx);
			height: 100%;
			border-radius: 6rpx;
			border: 1rpx solid rgba(0,0,0,.2);
			padding: 20rpx;
			input{
				width:100%;
				height: 100%;
				font-size: 26rpx;
				text-align: center;
			}
		}
		.btn{
			width: 140rpx;
			height: 100%;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			font-size: 26rpx;
			margin-left: 20rpx;
			background: #292929;
			height: 80rpx;
			border-radius: 10rpx;
		}
	}
	.myfriend{
		min-height: 100vh;
		background: #fff;
		.top{
			height: 80rpx;
			padding: 10rpx;
			margin: 30rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			background: #F8F8F8;
			border-radius: 80rpx;
			.item{
				display: flex;
				align-items: center;
				justify-content: center;
				font-size: 26rpx;
				width: 30%;
				height: 100%;
				border-radius: 60rpx;
				font-weight: bold;
			}
		}
		.content-box{
			margin: 30rpx;
			/* #ifdef APP-PLUS */
			height: calc(100vh - 340rpx);
			/* #endif */
			/* #ifdef H5 */
			height: calc(100vh - 260rpx);
			/* #endif */
			.item{
				display: flex;
				align-items: center;
				min-height: 100rpx;
				padding: 30rpx;
				border-radius: 10rpx;
				margin-bottom: 30rpx;
				.left{
					height: 80rpx;
					margin-right: 30rpx;
				}
				.right{
					width: calc(100% - 130rpx);
					.title{
						font-size: 26rpx;
						margin-bottom: 10rpx;
					}
					.name{
						font-size: 26rpx;
						color: rgba(0,0,0,.4);
						display: flex;align-items: center;justify-content: space-between;
					}
				}
			}
		}
	}
	
</style>